/*
 *
 */

class Resource {
	public constructor() {
		this.movieClipCache = {};
		this.effectCache = {};
		this.dragonBonesCache = {};
	}

	public getResByUrl(url:string,compFunc:Function ,thisObject:any ,type:string ):void {
		RES.getResByUrl(url, compFunc, thisObject, type);
	}

	public getItemIcon(id:number, compFunc:Function ,thisObject:any ,type:string) : void {
		var url:string = "resource/ui/ui_icon/item_" + id + ".png";
		RES.getResByUrl(url, compFunc, thisObject, type);
	}
	public getMallIcon(id:number, compFunc:Function ,thisObject:any ,type:string) : void {
		var url:string = "resource/ui/ui_icon/mall_" + id + ".png";
		RES.getResByUrl(url, compFunc, thisObject, type);
	}
	public getSkillIcon(id:number, compFunc:Function ,thisObject:any ,type:string) : void {
		var url:string = "resource/ui/ui_icon/skill_" + id + ".png";
		RES.getResByUrl(url, compFunc, thisObject, type);
	}

	public getNoticeIcon(id:number, compFunc:Function ,thisObject:any ,type:string) : void {
		var url:string = "resource/ui/ui_icon/notice_" + id + ".jpg";
		RES.getResByUrl(url, compFunc, thisObject, type);
	}

	public getHeroIcon(id:number, compFunc:Function ,thisObject:any ,type:string) : void {
		var url:string = "resource/ui/ui_icon/hero_" + id + ".png";
		RES.getResByUrl(url, compFunc, thisObject, type);
	}

	public dragonBonesCache:any;
	public getDragonBones(id:number, compFunc:Function ,thisObject:any) {
		
		var selfCache = this.dragonBonesCache;
		if (this.dragonBonesCache[id]) {
			var dragonbonesFactory = this.dragonBonesCache[id];
			// var armature:dragonBones.Armature = dragonbonesFactory.buildArmature("armatureName");
			// compFunc.call(thisObject, armature);
			return;
		}
		function createDragonBonesClass() {
			var dragonbonesData = null;
			var textureData = null;
			var textureAltas = null;
			function createDragonbones() {

				if (!dragonbonesData)return;
				if (!textureData)return;
				if (!textureAltas)return;

				// var dragonbonesFactory:dragonBones.EgretFactory = new dragonBones.EgretFactory();  
				// dragonbonesFactory.addDragonBonesData(dragonBones.DataParser.parseDragonBonesData(dragonbonesData));  
				// dragonbonesFactory.addTextureAtlas(new dragonBones.EgretTextureAtlas(textureAltas, textureData));
				// var armature:dragonBones.Armature = dragonbonesFactory.buildArmature("armatureName");
				// selfCache[id] = dragonbonesFactory;
				// compFunc.call(thisObject, armature);	
			}
			RES.getResByUrl("resource/anim/" + id + "/" + id + "_ske.json", function (obj:Object) {
				//将加载完的资源进行显示
				//console.log(obj);
				dragonbonesData = obj;
				createDragonbones();
			}, this, RES.ResourceItem.TYPE_JSON);
			RES.getResByUrl("resource/anim/" + id + "/" + id + "_tex.json", function (obj:Object) {
				//将加载完的资源进行显示
				//console.log(obj);
				textureData = obj;
				createDragonbones();
			}, this, RES.ResourceItem.TYPE_JSON);
			RES.getResByUrl("resource/anim/" + id + "/" + id + "_tex.png", function (obj:egret.Texture) {
				//将加载完的资源进行显示
				//console.log(obj);
				textureAltas = obj;
				createDragonbones();
			}, this, RES.ResourceItem.TYPE_IMAGE);
		}
		createDragonBonesClass ();
	}

	public movieClipCache:any;
	public getAnim(_mcName:string, compFunc:Function ,thisObject:any) {
		var selfCache = this.movieClipCache;
		if (this.movieClipCache[_mcName]) {
			var movieClipData = this.movieClipCache[_mcName];
			compFunc.call(thisObject, movieClipData);
			return;
		}
		function createMovieClipClass() {
			var movieClipJson = null;
			var movieClipTexture = null;
			function createMovieClip() {
				if (!movieClipJson)return;
				if (!movieClipTexture)return;
				var movieClipDataFactory:egret.MovieClipDataFactory = new egret.MovieClipDataFactory(movieClipJson, movieClipTexture);  
				var movieClipData = movieClipDataFactory.generateMovieClipData(_mcName);
				selfCache[_mcName] = movieClipData;
				compFunc.call(thisObject, movieClipData);
			}
			RES.getResByUrl("resource/assets/mc/" +_mcName + ".json", function (obj:Object) {
				//将加载完的资源进行显示
				movieClipJson = obj;
				createMovieClip();
			}, this, RES.ResourceItem.TYPE_JSON);
			RES.getResByUrl("resource/assets/mc/" +_mcName + ".png", function (texture:egret.Texture) {
				//将加载完的资源进行显示
				movieClipTexture = texture;
				createMovieClip();
			}, this, RES.ResourceItem.TYPE_IMAGE);
		}
		createMovieClipClass ();
	}

	public effectCache:any;
	public getEffect(anim:string, compFunc:Function ,thisObject:any) {
		var selfCache = this.effectCache;
		if (this.effectCache[anim]) {
			//var movieClipDataFactory:egret.MovieClipDataFactory = this.animCache[id+'_'+anim];
			var movieClipData = this.effectCache[anim];
			compFunc.call(thisObject, movieClipData);
			return;
		}
		function createMovieClipClass() {
			var movieClipJson = null;
			var movieClipTexture = null;
			function createMovieClip() {
				if (!movieClipJson)return;
				if (!movieClipTexture)return;
				//console.log(movieClipJson);
				//console.log(movieClipData);
				var movieClipDataFactory:egret.MovieClipDataFactory = new egret.MovieClipDataFactory(movieClipJson, movieClipTexture);  
				var movieClipData = movieClipDataFactory.generateMovieClipData("");
				selfCache[anim] = movieClipData;
				compFunc.call(thisObject, movieClipData);
			}
			RES.getResByUrl("resource/effect/" +anim + ".json", function (obj:Object) {
				//将加载完的资源进行显示
				movieClipJson = obj;
				createMovieClip();
			}, this, RES.ResourceItem.TYPE_JSON);
			RES.getResByUrl("resource/effect/" + anim + ".png", function (texture:egret.Texture) {
				//将加载完的资源进行显示
				movieClipTexture = texture;
				createMovieClip();
			}, this, RES.ResourceItem.TYPE_IMAGE);
		}
		createMovieClipClass ();
	}
} 